package com.magic.zhixin.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "返回类")
public class Result<T> {
    @ApiModelProperty(value = "返回代码，200表示成功，-1表示失败，901表示token过期或者无效")
    private int code = 200;
    @ApiModelProperty(value = "返回信息")
    private String message = "操作成功";
    @ApiModelProperty(value = "返回数")
    private    T data = null;
    private static String defaultData = new String();
    public final static int OK_VALUE = 200;
    public final static int FAIL_VALUE = -1;

    private Result() {
    }

    public Result(int _code, String _msg, T _data) {
        code = _code;
        message = _msg;
        data = _data;
    }

    public static Result OkResult(Object data) {
        if (data == null) {
            data = defaultData;
        }
        return new Result(200, "操作成功", data);
    }

    public static Result FailedResult(String msg) {
        return new Result(-1, msg, defaultData);
    }


}
